package server

import (
	"encoding/json"
	"html/template"
	"net/http"
)

type Msg struct {
	Name  string
	Phone string
	Email string
}

func Login(w http.ResponseWriter, r *http.Request) {
	r.ParseForm()
	if r.Method == "GET" {
		t, _ := template.ParseFiles("View/login.html")
		t.Execute(w, nil)
	} else {
		res := &Msg{r.Form["username"][0], "10086", "10086@mail.com"}
		t, _ := template.ParseFiles("View/info.html")
		t.Execute(w, res)
	}
}

type JSres struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

func JSTest(w http.ResponseWriter, r *http.Request) {
	res := &JSres{200, "Success"}
	msg, _ := json.Marshal(res)
	w.Write(msg)
}
